<div id="all-product">    

    <table class = "data-table" border="1" >
        <tr class="table-header" height="35px">
           <th width="100px">Mã sản phẩm</th>
           <th width="220px">Tên sản phẩm</th>
           <th width="110px">Giá</th>
           <th width="100px">Hình</th>
           <th width="120px">Khuyến mãi</th>
           <th width="80px">Bảo hành</th>
           <th width="110px">Ngày cập nhật</th> 
           <th width="80px">Sửa</th>
           <th width="80px">Xóa</th>
        </tr>
        <?php foreach ($this->products as $item_product){?>
            <tr height="20px">
                <td style="text-align: center;"><?php echo $item_product['product_id']?></td>
                <td><?php echo $item_product['product_name']?></td>
                <td style="text-align: center;"><?php echo $item_product['product_price']?></td>
                <td class="image-product"><img src="<?php echo $this->baseUrl('default/images/products/').$item_product['product_image']?>" alt="san pham"/></td>
                <td><?php echo substr($item_product['product_promotion'], 0, 18) .'...'?></td>
                <td style="text-align: center;"><?php echo $item_product['product_warranty']?></td>
                <td style="text-align: center;"><?php $date = date_create($item_product['product_dateupdate']); echo date_format($date, 'd-m-Y');?></td>
                <td class="edit-icon" ><a href="<?php echo $this->baseUrl('admin/product/update/productid/').$item_product['product_id']?>" title="sửa" class="edit"><img src="<?php echo $this->baseUrl('admin/images/')?>edit.ico" alt="sua"/></a></td>
                <td class="del-icon" ><a href="<?php echo $this->baseUrl('admin/product/delete/id/').$item_product['product_id']?>" title="Xóa" class="del"><img src="<?php echo $this->baseUrl('admin/images/')?>remove.ico" alt="xoa"/></a></td>
            </tr>
        <?php }?>
    </table>
    <?php if($this->products->Count() > 1) {?>                
        <div id="paginator">
             <?php echo $this->paginationControl($this->products, 'Sliding', 'index/pagination.phtml')?>
        </div>
    <?php }?>
    
    <div class="dialog" title="Thông báo"></div>
</div>


<script>
//show all product
$(document).ready(function(){
	$("#paginator a").click(function(){
	    var link = $(this).attr("href");	    
	    $.get(link, null, function(rdata){
		    $("#all-product").empty();
	        $("#all-product").html(rdata);	        
		    });
	    
	    return false;
		});
});

//delete product
$(document).ready(function(){
    $(".del-icon a").click(function(){
        var _this=$(this);
        $(".dialog").html('<div class="message"><p>Bạn có muốn xóa sản phẩm này không?</p></div>')
        .dialog({
            resizable: false,
            modal: true,
            buttons: {
                "Có": function(){
                	var link = _this.attr("href");
                    $.ajax({
                        url: link,
                        }); 
                    _this.parent().parent().remove();                    
                    $(this).dialog("close");
                    },
                    "Không": function(){
                        $(this).dialog("close");
                        }
                }
            });
        return false;
        });
});


//color row of table
$(document).ready(function(){
    $("tr").filter(':odd').addClass('alt');
	
});



</script>